#include <cstdio>
using namespace std;
int main(void){
    int cu,d;
    while(~scanf("%d%d",&cu,&d)){
        if(cu==0 && d==0){
            break;
        }
        int ans=0;
        while(cu%60!=0){
            cu=cu*(d+1)%60;
            ans++;
            if(ans>1000){
                printf("Impossible\n");
                break;
            }
        }
        if(ans<=1000){
            printf("%d\n",ans);
        }
    }
    return 0;
}